package com.huaxin.device.mapping;

import com.huaxin.device.dto.enums.DeviceZoneType;
import com.huaxin.device.dto.request.AddDeviceZoneReqDTO;
import com.huaxin.device.dto.request.UpdateDeviceZoneReqDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface DeviceZoneMapping {

    @Mapping(target = "zoneType", ignore = true)
    com.huaxin.device.models.DeviceZone toEntity(AddDeviceZoneReqDTO in);

    @AfterMapping
    default void afterMapping(AddDeviceZoneReqDTO in, @MappingTarget com.huaxin.device.models.DeviceZone entity) {
        entity.setZoneType(DeviceZoneType.of(in.getZoneType()));
    }

    @Mapping(target = "zoneType", ignore = true)
    void updateEntity(UpdateDeviceZoneReqDTO in, @MappingTarget com.huaxin.device.models.DeviceZone entity);

    @AfterMapping
    default void afterMapping(UpdateDeviceZoneReqDTO in, com.huaxin.device.models.DeviceZone entity) {
        entity.setZoneType(DeviceZoneType.of(in.getZoneType()));
    }
}